#include "StdAfx.h"
#include "ManGrid.h"
CManGrid* CManGrid::pInstance = NULL;
CManGrid::CManGrid(void)
{
}

CManGrid::~CManGrid(void)
{
}
CManGrid *CManGrid::GetInstance()
{
	if(pInstance==NULL)
	{
		pInstance =new CManGrid;
	}
	return pInstance;
}

CString CManGrid::RegisterWindowClass (LPCTSTR lpszClassNamePrefix)
{
	ASSERT (lpszClassNamePrefix != NULL);

	//-----------------------------
	// Register a new window class:
	//-----------------------------
	HINSTANCE hInst = AfxGetInstanceHandle();
	UINT uiClassStyle = CS_DBLCLKS;
	HCURSOR hCursor = ::LoadCursor (NULL, IDC_ARROW);
	HBRUSH hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

	CString strClassName;
	strClassName.Format (_T("%s:%x:%x:%x:%x"), 
		lpszClassNamePrefix,
		(UINT_PTR)hInst, uiClassStyle, (UINT_PTR)hCursor, (UINT_PTR)hbrBackground);

	//---------------------------------
	// See if the class already exists:
	//---------------------------------
	WNDCLASS wndcls;
	if (::GetClassInfo (hInst, strClassName, &wndcls))
	{
		//-----------------------------------------------
		// Already registered, assert everything is good:
		//-----------------------------------------------
		ASSERT (wndcls.style == uiClassStyle);
	}
	else
	{
		//-------------------------------------------
		// Otherwise we need to register a new class:
		//-------------------------------------------
		wndcls.style = uiClassStyle;
		wndcls.lpfnWndProc = ::DefWindowProc;
		wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
		wndcls.hInstance = hInst;
		wndcls.hIcon = NULL;
		wndcls.hCursor = hCursor;
		wndcls.hbrBackground = hbrBackground;
		wndcls.lpszMenuName = NULL;
		wndcls.lpszClassName = strClassName;

		if (!AfxRegisterClass (&wndcls))
		{
			AfxThrowResourceException();
		}
	}

	return strClassName;
}
CRect CManGrid::TransformX_S(const CRect &rc,CSize sz,int nFreezeColumns)
{
	CRect retRc;
	CPoint pT=CPoint(rc.left,rc.top);
	if (nFreezeColumns)
	{
		pT.Offset(CSize(0,-(sz.cy)));
		retRc=CRect(pT,CSize(rc.Width()-sz.cx,rc.Height()));
		return retRc;
	}
	else
	{
		pT.Offset(-sz);
		retRc=CRect(pT,CSize(rc.Width(),rc.Height()));
		return retRc;
	}
}

CRect CManGrid::Transform1X_S(const CRect &rc,CSize sz,int nIndex,int nFreezeColumns)
{	
	CRect retRc	=rc;
	if (nFreezeColumns>nIndex)
	{
		retRc.OffsetRect(CSize(0,-(sz.cy)));
	}else
	{
		retRc.OffsetRect(-sz);
	}
	return retRc;
}
CPoint	CManGrid::Transform1X_S(const CPoint &pt,CSize sz,int nIndex,int nFreezeColumns)
{
	CPoint retPT=pt;
	if(nFreezeColumns>nIndex)
	{
		retPT.Offset(CSize(0,-(sz.cy)));
	}else
	{
		retPT.Offset(-sz);
	}
	return retPT;
}

CPoint	CManGrid::Transform1S_X(const CPoint &pt,CSize sz,int nFreezelenght)
{
	CPoint retPT=pt;
	if(pt.x<nFreezelenght)
	{
		retPT.Offset(CSize(0,(sz.cy)));
	}else
	{
		retPT.Offset(sz);
	}
	return retPT;
}

CRect	CManGrid::Transform2X_S(const CRect &rc,CSize sz,int nIndex,int nFreezeColumns)
{
	CRect retRc=rc;
	if (nFreezeColumns<=nIndex)
	{
		retRc.OffsetRect(CSize(-(sz.cx),0));
	}
	return retRc;
}
CPoint	CManGrid::Transform2X_S(const CPoint &pt,CSize sz,int nIndex,int nFreezeColumns)
{
	CPoint retpT=pt;
	if (nFreezeColumns<=nIndex)
	{
		retpT.Offset(CSize(-(sz.cx),0));
	}
	return retpT;
}
CPoint	CManGrid::Transform2S_X(const CPoint &pt,CSize sz,int nFreezelenght)
{
	CPoint retPT=pt;
	if(pt.x<nFreezelenght)
	{
		retPT.Offset(CSize(0,(sz.cy)));
	}else
	{
		retPT.Offset(sz);
	}
	return retPT;
}

// static CRect	On_Convser3X_S(const CRect &rc,CSize sz);
// static CPoint	On_Convser3X_S(const CPoint &pt,CSize sz);
// static CRect	On_Convser3S_X(const CRect &rc,CSize sz);
// static CPoint	On_Convser3S_X(const CPoint &pt,CSize sz);